import { HeaderResolver, I18nModule } from 'nestjs-i18n';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AllConfigType } from '@/config/config.type';
import path from 'path';
export default I18nModule.forRootAsync({
  useFactory: (configService: ConfigService<AllConfigType>) => ({
    fallbackLanguage: configService.getOrThrow('app.fallbackLanguage', {
      infer: true,
    }),
    loaderOptions: { path: path.join(__dirname, './lang/'), watch: true },
  }),
  resolvers: [
    {
      use: HeaderResolver,
      useFactory: (configService: ConfigService<AllConfigType>) => {
        return [
          configService.get('app.headerLanguage', {
            infer: true,
          }),
        ];
      },
      inject: [ConfigService],
    },
  ],
  imports: [ConfigModule],
  inject: [ConfigService],
});
